/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/

#include "application.h"
#include "mainwindow.h"
#include "serverconnection.h"
#include "serverevents.h"
#include "game.h"
#include "util.h"

#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 2
#define CLIENT_VERSION_REVISION 0

using namespace client;

Application::Application(int argc, char* argv[]):
    QApplication(argc, argv),
    mp_game(0),
    m_mode(DefaultMode)
{
    randomize();
    setSignalHandlers();

    setApplicationName("KShootout");
    setApplicationVersion(QString("%1.%2.%3").arg(CLIENT_VERSION_MAJOR).
                                              arg(CLIENT_VERSION_MINOR).
                                              arg(CLIENT_VERSION_REVISION));

    mp_serverConnection = new ServerConnection();
    ///   @todo
    //connect(mp_serverConnection, SIGNAL(

    mp_mainWindow = new MainWindow();
    mp_mainWindow->show();
}

Application::~Application()
{
    delete mp_mainWindow;
    delete mp_serverConnection;
}

void Application::onServerEvent(const ServerEventDataPtr& serverEvent)
{
    switch (serverEvent->t()) {
    case ServerEventData::EnterGameType:
        if (m_mode == GameMode) {
            qCritical("Application: EnterGameEvent received, but client already in game!");
        } else {
            m_mode = GameMode;
            mp_game = new Game(serverEvent.staticCast<EnterGameEventData>());
        }
        break;
    case ServerEventData::ExitGameType:
        break;

    }

}

